package com.hmdp.config;

import com.hmdp.interceptor.LoginInterceptor;
import com.hmdp.interceptor.UserRefreshInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;

@Configuration
@Slf4j
/**
 *自定义WebMvcConfigurer，注册拦截器
 */
public class SpringWebMvcConfig extends WebMvcConfigurationSupport {

    @Resource
    private UserRefreshInterceptor userInterceptor;//刷新用户信息拦截器
    @Resource
    private LoginInterceptor loginInterceptor;//登入校验拦截器
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//拦截所有路径
                .excludePathPatterns(//排除不需要拦截的路径
                        "/shop/**",
                        "/voucher/**",
                        "/shop-type/**",
                        "/upload/**",
                        "/blog/hot",
                        "/user/code",
                        "/user/login"
                ) //排除登录路径,/**/login表示匹配所有以/login开头的路径
                .order(1); //拦截器的顺序
        registry.addInterceptor(userInterceptor)
                .addPathPatterns("/**").order(0);//0表示优先级最高，拦截所有路径


    }
}
